
package uloha3;

import java.io.BufferedWriter;
import java.io.File;
import java.io.FileWriter;
import java.io.IOException;
import java.util.logging.Level;
import java.util.logging.Logger;

public class DataWriter {
    
    String menoVystupnehoSuboru;
    String textNaZapis;
    public DataWriter(String menoVystupu, String textNaZapis)
    {
        menoVystupnehoSuboru = menoVystupu;
        this.textNaZapis = textNaZapis;
    }
    
    public void zapisSubor()
    {
        BufferedWriter out = null;
        File vystupnySubor = null;
        
        try {
            vystupnySubor = new File(menoVystupnehoSuboru);
            if (!vystupnySubor.exists()) {
                    vystupnySubor.createNewFile();
                }
            out = new BufferedWriter(new FileWriter(vystupnySubor));
            out.write(textNaZapis);
        } catch (IOException ex) {
            Logger.getLogger(DataWriter.class.getName()).log(Level.SEVERE, null, ex);
        }
        finally{
            try {
                out.close();
            } catch (IOException ex) {
                Logger.getLogger(DataWriter.class.getName()).log(Level.SEVERE, null, ex);
            }
            
        }
        
    }
}
